package com.guhappy.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.guhappy.action.model.Stock;
import com.guhappy.util.business.BusinessUtil;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author bduan
 */
public class JsonSample extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = -2223948287805083119L;
	private static final Log log = LogFactory.getLog(JsonSample.class);
	private List<Stock> reloadList;
	private SessionMap<String, String> myMap;
   
	private String area;

	public String execute() throws Exception {
		return SUCCESS;
	}

	public String listArea() {
		log.info("build json lists area : " + area);
		if (area != null && !area.trim().equals("")) {
			reloadList = BusinessUtil.regionListUtil(myMap.get(area));
		}
		return SUCCESS;
	}

	public String getJSON() {
		return listArea();
	}

	public List<Stock> getReloadList() {
		return reloadList;
	}

	public void setReloadList(List<Stock> reloadList) {
		this.reloadList = reloadList;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getArea() {
		return area;
	}

	public void setSession(Map<String, Object> sessionMap) {
		myMap = (SessionMap)sessionMap;
        myMap.put("United States", "1");
        myMap.put("Canada", "2");
        myMap.put("North America", "3");
        myMap.put("China", "4");
        myMap.put("Hongkong", "5");
        myMap.put("Taiwan", "6");
        myMap.put("Singapore", "7");
        myMap.put("Austrilia", "8");
        myMap.put("London", "9");
        myMap.put("Korea", "10");
	}
}
